// pages/ebook/description/description.js
//var arr=[];
var app = getApp(); 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: '3',
    imageUrl:"jinghu.png",
    title:"镜湖",
    author:"庆山",
    logo:'left.png',
    human11:"human11.png",
    id:"id",
    time:"time",
    inf:"我也不知道她写了啥为了凑字数只能瞎编我也很无奈啊我也不知道她写了啥为了凑字数只能瞎编我也很无奈啊我也不知道她写了啥为了凑字数只能瞎编我也很无奈啊我也不知道她写了啥为了凑字数只能瞎编我也很无奈啊",
    auinf:" ",
    num:12,
    bookurl:" ",
    uid1:" ",
    uid2: " ",
    inf1: " ",
    inf2: " ",
    time1: " ",
    time2: " ",
  },
  tocatalog: function (e){
    wx.navigateTo({
      url: 'catalog/catalog?num='+this.data.num+"&id="+this.data.type+"&name="+this.data.title
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({
      type: options.type,
    });
    console.log(options.type);
    var type = options.type;
    /**
     * 请求数据库获取数据
     */
    wx.request({
      url: 'http://localhost:8088/penglaige/showdescription.php', //数据库查询所对应的url
      data: {
        bookid:that.data.type,
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' //一定要换成这个
      },
      success: function (res) {
        console.log(res.data);
        that.setData({
          imageUrl:decodeURIComponent(res.data.cover),
          title:res.data.name,
          author:res.data.author,
          auinf:res.data.writer,
          inf:res.data.bookcontent,
          num:res.data.chapter,
          uid1:res.data.uid1,
          uid2:res.data.uid2,
          time1:res.data.time1,
          time2:res.data.time2,
          inf1:res.data.cocontent1,
          inf2:res.data.cocontent2
       //   that.id=res.data.id;
       //   that.time=res.data.time;
       //   that.coinf=res.data.cocontent;
       //   that.human11=res.data.human;
       //   taht.num=res.data.num;
          });
        var keyAry = [];
        var valueAry = [];
        for (var key in res.data) {
          keyAry.push(key);
          valueAry.push(res.data[key]);
        }
        app.globalData.arr.splice(0, app.globalData.arr.length);
        for (var i = 7; i <= 6 +parseInt(res.data.chapter);i++){
          app.globalData.arr.push(valueAry[i]);
          console.log(app.globalData.arr);
          }
      },
      fail: function (res) {
        console.log("失败");
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})